home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17727 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  123 lines

  1. Path: siemens.ch!news
  2. From: mrw@tobago.siemens.ch (Waeckerlin Marc)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Circular Usage (forward declaration?)
  5. Date: 17 Apr 1996 08:41:21 GMT
  6. Organization: Siemens Schweiz AG
  7. Message-ID: <MRW.96Apr17104121@tobago.siemens.ch>
  8. References: <MRW.96Apr16184800@tobago.siemens.ch>
  9.     <ltu3ykovzc.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  10.     <31747631.5970@datalytics.com>
  11. NNTP-Posting-Host: 150.10.54.28
  12. In-reply-to: Rob Stewart's message of Wed, 17 Apr 1996 00:40:17 -0400
  13.  
  14. Hi
  15.  
  16. Thank you for the answers.
  17.  
  18. I know this way, but it does not work in my case, since the members "x"
  19. absolutely must be no pointers.
  20. Speaking more exactly, they are pointers, but they are smart pointers.
  21. In another example, you could get somnething like this, where "CPointer"
  22. is a smart pointer:
  23.  
  24. class CCompany
  25. {
  26.   protected:
  27.  
  28.     CPointer<CEmployee> m_emp;
  29.     
  30.   public:
  31.  
  32.     set(CEmployee &p_emp)
  33.     {
  34.       m_emp = &p_emp;
  35.     }
  36. };
  37.  
  38.  
  39. class CEmployee
  40. {
  41.   protected:
  42.  
  43.     CPointer<CCompany> m_comp;
  44.  
  45.   public:
  46.     
  47.     set(CCompany &p_comp)
  48.     {
  49.       m_comp = &p_comp;
  50.     }
  51. };
  52.  
  53.  
  54. Best Regards
  55. Marc
  56.  
  57. In article <31747631.5970@datalytics.com> Rob Stewart <stew@datalytics.com> writes:
  58.  
  59. > From: Rob Stewart <stew@datalytics.com>
  60. > Newsgroups: comp.lang.c++
  61. > Date: Wed, 17 Apr 1996 00:40:17 -0400
  62. > Organization: Datalytics, Inc.
  63. > Enno Sandner wrote:
  64. > > 
  65. > > In article <MRW.96Apr16184800@tobago.siemens.ch> mrw@tobago.siemens.ch (Waeckerlin Marc) writes:
  66. > > 
  67. > >    How do you realize this in C++:
  68. > >    (the whole problem is much more complex, but it can be reduced to that)
  69. > > 
  70. > >    class A
  71. > >    {
  72. > >        B x;
  73. > >    };
  74. > > 
  75. > >    class B
  76. > >    {
  77. > >        A x;
  78. > >    };
  79. > > 
  80. > > There's no way -- use pointers or references instead, i.e. dynamicly
  81. > > allocate the appropriate instance of class 'A' or class 'B'.
  82. > > 
  83. > >         Enno
  84. > Enno is correct, except you also need to forward declare one of 
  85. > the classes:
  86. > class B;
  87. > class A
  88. > {
  89. >    B* px;
  90. > };
  91. > class B
  92. > {
  93. >    A x;
  94. > };
  95. > -- 
  96. > Rob Stewart    | My opinions are generally my own.  They do
  97. > Datalytics, Inc.| not necessarily reflect those of my employer.
  98. -- 
  99.                     \|||/             SIEMENS SCHWEIZ AG
  100.                     /Q Q\     
  101. ================oOOo=\Y/=oOOo====================================
  102. | Marc WΣckerlin             | E-mail: mrw@siemens.ch           |
  103. | Siemens Schweiz EUQ2/I-49  |                                  |
  104. | Albisriederstrasse 245     | Phone:  ++41 1 495 32 29         |
  105. | CH-8047 Zⁿrich             | Fax:    ++41 1 495 44 37         |
  106. |---------------------------------------------------------------|
  107. |                Homepage: http://www.siemens.ch                |
  108. \---------------------------------------------------------------/
  109. Visit my personal homepage at:  http://www.access.ch/~mwaeckerlin
  110.                     
  111.  _______________                                   ______________
  112. |joke of the day|                                 / just kidding \
  113. ==================================================================
  114. Smash forehead on keyboard to continue.....
  115. ==================================================================
  116.